#!/bin/bash -e

source $PATH_SCRIPTS/get-package.sh
source $PATH_SCRIPTS/tool-util.sh

# present the header
echo	"


=====================================================================

           Utility to generate level 3 tools
 
=====================================================================



"

set +h
umask 022
LC_ALL=POSIX
LFS_TGT=$(uname -m)-$JAIL_NAME-linux-gnu
PATH=/tools/bin:/bin:/usr/bin
export LC_ALL LFS_TGT PATH MAKEFLAGS





# ===============================================================
initDir "5.10." "tcl8.5.12-src"
	cd $SRC_DIR
	cd unix
	./configure --prefix=/tools >> $CRTLOG
	make >> $CRTLOG
	make install >> $CRTLOG

	# Make the installed library writable so debugging symbols can be removed later:
	chmod -v u+w /tools/lib/libtcl8.5.so

	# Install Tcl's headers. The next package, Expect, requires them to build.
	make install-private-headers >> $CRTLOG

	# Now make a necessary symbolic link:
	ln -sv tclsh8.5 /tools/bin/tclsh
rDir
initDir "5.11." "expect5.45"
	cd $SRC_DIR
	# First, force Expect's configure script to use /bin/stty instead 
	# of a /usr/local/bin/stty it may find on the host system. 
	# This will ensure that our test suite tools remain sane 
	# for the final builds of our toolchain: 
	cp -v configure{,.orig}
	sed 's:/usr/local/bin:/bin:' configure.orig > configure

	./configure --prefix=/tools --with-tcl=/tools/lib \
	  --with-tclinclude=/tools/include > $CRTLOG
	  
	make >> $CRTLOG
	# SCRIPTS="" This prevents installation of the 
	# supplementary Expect scripts, which are not needed.
	make SCRIPTS="" install >> $CRTLOG
rDir
doItAll "5.12." "dejagnu-1.5"
doItAll "5.13." "check-0.9.8"
initDir "5.14." "ncurses-5.9"
	cd $SRC_DIR
	./configure --prefix=/tools --with-shared \
		--without-debug --without-ada --enable-overwrite >> $CRTLOG
finishDir
initDir "5.15." "bash-4.2"
	cd $SRC_DIR
	patch -Np1 -i $PATH_PKGCACHE/bash-4.2-fixes-9.patch >> $CRTLOG
	./configure --prefix=/tools --without-bash-malloc >> $CRTLOG
finishDir
ln -sv bash /tools/bin/sh
initDir "5.16." "bzip2-1.0.6"
	cd $SRC_DIR
	make >> $CRTLOG
	make PREFIX=/tools install >> $CRTLOG
rDir
initDir "5.17." "coreutils-8.19"
	cd $SRC_DIR
	./configure --prefix=/tools \
		--enable-install-program=hostname  >> $CRTLOG
finishDir
initDir "5.18." "diffutils-3.2"
	cd $SRC_DIR
	# Fix an incompatibility between this package and Glibc-2.16.0: 
	sed -i -e '/gets is a/d' lib/stdio.in.h
	./configure --prefix=/tools  >> $CRTLOG
finishDir
doItAll "5.19." "findutils-4.4.2"
doItAll "5.20." "gawk-4.0.1"
initDir "5.22." "gettext-0.18.1.1"
	cd $SRC_DIR
	# Fix an incompatibility between this package and Glibc-2.16.0:
	sed -i -e '/gets is a/d' gettext-*/*/stdio.in.h

	cd gettext-tools
	EMACS="no" ./configure --prefix=/tools --disable-shared  >> $CRTLOG
	make -C gnulib-lib  >> $CRTLOG
	make -C src msgfmt  >> $CRTLOG
	cp -v src/msgfmt /tools/bin
rDir
doItAll "5.23." "grep-2.14"
doItAll "5.24." "gzip-1.5"
initDir "5.25." "m4-1.4.16"
	cd $SRC_DIR
	sed -i -e '/gets is a/d' lib/stdio.in.h
	./configure --prefix=/tools  >> $CRTLOG
finishDir
doItAll "5.26." "make-3.82"
doItAll "5.27." "patch-2.7.1"
initDir "5.28." "perl-5.16.1"
	cd $SRC_DIR
	patch -Np1 -i $PATH_PKGCACHE/perl-5.16.1-libc-2.patch >> $CRTLOG
	sh Configure -des -Dprefix=/tools >> $CRTLOG
	make >> $CRTLOG
	cp -v perl cpan/podlators/pod2man /tools/bin
	mkdir -pv /tools/lib/perl5/5.16.1
	cp -Rv lib/* /tools/lib/perl5/5.16.1
rDir
doItAll "5.29." "sed-4.2.1" "bz2"

initDir "5.30." "tar-1.26" "bz2"
	cd $SRC_DIR
	sed -i -e '/gets is a/d' gnu/stdio.in.h
	./configure --prefix=/tools >> $CRTLOG
finishDir
initDir "5.31." "texinfo-4.13a"
	cd $SRC_DIR
	./configure --prefix=/tools >> $CRTLOG
finishDir
doItAll "5.32." "xz-5.0.4" "xz"
# ===============================================================




# present the footer
echo	"


=====================================================================

           Utility to generate level 3 tools done
 
=====================================================================



"
